import { HashMap } from "../../api/struct/HashMap";
import { E_HandBookGroup } from "../defs/hand_book/E_HandBookGroup";
import { E_ItemType } from "../defs/item/E_ItemType";
import { CDHandBook } from "../excel/CDHandBook";


/**
 * 扩展-图鉴
 */
export abstract class CEHandBook {
    /**图鉴类型 */
    public static handBookTypeMap = new HashMap<number, CDHandBook[]>();
    /**分组数据 */
    public static groupMap = new HashMap<E_HandBookGroup, CDHandBook[]>();
    /**图鉴道具类型 */
    public static itemTypeMap = new HashMap<E_ItemType, HashMap<number, CDHandBook>>();


    /**初始化 */
    public static init(): void {
        const vs = CDHandBook.datas.getValues();
        for (let i = 0, len = vs.length; i < len; i++) {
            const config = vs[i];

            //图鉴类型
            {
                let list = this.handBookTypeMap.get(config.handbook);
                if (!list) {
                    list = [];
                    this.handBookTypeMap.put(config.handbook, list);
                }
                list.push(config);
            }

            //分组
            {
                let list = this.groupMap.get(config.group);
                if (!list) {
                    list = [];
                    this.groupMap.put(config.group, list);
                }
                list.push(config);
            }

            //道具类型
            {
                let map = this.itemTypeMap.get(config.itemType);
                if (!map) {
                    map = new HashMap<number, CDHandBook>();
                    this.itemTypeMap.put(config.itemType, map);
                }
                map.put(config.itemid, config);
            }
        }
    }


    /**
     * 在图鉴中的状态
     * @param itemType 
     * @param itemId 
     * @returns
     */
    public static getItemBookConfig(itemType: E_ItemType, itemId: number): CDHandBook {
        const map = this.itemTypeMap.get(itemType);
        if (map) {
            const v = map.get(itemId);
            return v;
        }
        return null;
    }
}